#pragma once
#include<string>
#include<cstddef>
#include <boost/date_time/posix_time/posix_time.hpp>
#include <odb/nullable.hxx>
#include <odb/core.hxx>

#pragma db object //声明这个对象是一个数据库对象，即编译器要使用这个对象制作一个数据库的表
class Classes
{
public:
    Classes(){}; 
    Classes(const std::string& name):_name(name){};

    void name(const std::string& name){_name =name;}

    std::string name(){return _name;}
private:
    friend class odb::access;
    #pragma db column("id") id auto//指定下面一个变量为表的主键，auto和数据库的AUTO_INCREMENT意思一样
    unsigned int _id;
    #pragma db column("name")
    std::string _name;
};


#pragma db object
class Student
{
public:
    Student(){};
    Student(const unsigned int classes_id,const std::string& name,const unsigned short year)
    :_classes_id(classes_id),_name(name),_year(year){};
    unsigned int id() {return _id;};
    unsigned int classes_id() {return _classes_id;};
    std::string name() {return _name;};
    odb::nullable<unsigned short> year() {return _year;};

    void name(const std::string &name) { _name = name; }
    void year(unsigned short num) { _year = num; }
    void classes_id(unsigned long cid) { _classes_id = cid; }
private:
    friend class odb::access;

    #pragma db column("id") id auto
    unsigned int _id;
    #pragma db column("class_id") index
    unsigned int _classes_id;
    #pragma db column("name")
    std::string _name;
    #pragma db column("year")
    odb::nullable<unsigned short> _year;//年纪
};
//查询所有的学生信息，并显示班级名称
#pragma db view object(Student)\
                object(Classes = classes : Student::_classes_id == classes::_id)\
                query((?))
struct classes_student {
    #pragma db column(Student::_id)
    unsigned int id;
    #pragma db column(Student::_name)
    std::string name;
    #pragma db column(Student::_year)
    odb::nullable<unsigned short> year;
    #pragma db column(classes::_name)
    std::string classes_name;
};
//(?)表示外部自定义查询条件
#pragma db view query("select name from Student where" + (?))
//#pragma db view object(Student) query((?))
struct all_name {
    
    // #pragma db column(Student::_id)
    // unsigned int id;
    //#pragma db column(Student::_name)
    std::string n;
};
